package gases.as3.librarys.components.skin.utils
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;

	/**
	 * 皮肤工具类 
	 * @author gases
	 * 
	 */	
	public class SkinUtils
	{
		public function SkinUtils()
		{
		}
		
		public static function clearSkinData(skin:*):void
		{
			if(skin is Bitmap)
			{
				(skin as Bitmap).bitmapData.dispose();
				return;
			}
			if(skin is BitmapData)
			{
				(skin as BitmapData).dispose();
				return;
			}
			
			if(skin is Sprite)
			{
				clearAllChildren(skin);
				return;
			}
			if(skin is Shape)
			{
				(skin as Shape).graphics.clear();
				return;
			}
			if(skin is MovieClip)
			{
				clearAllChildren(skin);
				return;
			}
		}
		
		public static function clearAllChildren(skin:DisplayObjectContainer):void
		{
			if(skin is MovieClip)
			{
				(skin as MovieClip).stop();
			}
			
			var leng:int = skin.numChildren;
			for(var i:int = 0; i < leng; i++)
			{
				var sp:DisplayObject = skin.removeChildAt(0);
				clearSkinData(sp);
			}
		}
	}
}



